import { Component, OnDestroy } from '@angular/core';

import { brandProductService } from './brand.product.service';

import { ProductBase } from '../../product/product.base';

import { Util } from '../../../utils/util';

import { AsyncLocalStorage } from 'angular-async-local-storage';

import { ToastyService } from '../../../modules/ng2-toasty';

@Component({
  selector: 'brand-product',
  templateUrl: './brand.product.html',
  providers: [brandProductService]
})

export class BrandProductComponent extends ProductBase {

  brandInfo: any;
  param: any = {
    brandName: '',
    catName: '',
    rows: 10,
    sort: 'sellMoney',
    sortType: 'desc',
    start: 0
  };

  eventOff: any;
  catNameList:any;
  constructor(public util: Util, public toastyService:ToastyService, public service: brandProductService,public asyncStore:AsyncLocalStorage) {
    super(service, util,toastyService );

    this.brandInfo = this.util.sessionStore().get('brandDetail');

    this.setParam(this.brandInfo);

    // console.log(this.brandInfo);

    this.getHttp(this.param);

    // xs
    this.asyncStore.getItem('brandCatgory').subscribe((dataList) => {
      this.catNameList = dataList;
    });

  }
  //类目
  catNameChange(catName = ''){
    if(catName == this.param.catName){
      return;
    }
    this.param.catName = catName;
    this.getHttp(this.param);
  }

  // 店铺类型切换
  shopType:any='';
  // shopType Change
  shopTypeChange(data) {

    console.log(data);

    if (this.param.shopType === data) {
      return;
    }

    this.param.shopType = data;

    this.getHttp(this.param);

  }

  //
  searchText:any;
  search(){
    if(this.searchText == this.param.q){
      return;
    }
    this.searchText = this.param.q;
    this.getHttp(this.param);
  }

  ngOnDestroy() {
    if (this.eventOff) {
      this.eventOff.unsubscribe();
    }

    if (this.busy) {
      this.busy.unsubscribe();
    }

    if (this.exportBusy) {
      this.exportBusy.unsubscribe();
    }
  }

  setParam(data) {

    this.param.brandName = data.brandName;

    this.param.catName = data.categoryName == "/" ? "" : data.categoryName;
  }



  getHttp(param) {
    var res = {"code":0,"msg":"成功","data":{"value":[{"date":"2017-12-03 00:00:00","numberId":"553607889944","title":"New Balance 男女童靴子 中大童 儿童雪地靴加绒 短靴KB996SXY","picUrl":"//g-search2.alicdn.com/img/bao/uploaded/i4/i3/1119887712/TB13MGPfZjI8KJjSsppXXXbyVXa_!!0-item_pic.jpg","loc":"江苏苏州","propertyValue":"适用性别:女 男 中性,品牌:NEW BALANCE,货号:KB996SQY,鞋底材质:橡胶,上市年份季节:2017年秋季,颜色分类:KB996S3Y/肉粉色 KB996S4Y/古铜色 KB996SQY/桔色 KB996SXY/墨绿色,尺码:28 28.5 30 31 32.5 33.5 35 35.5 36 37 37.5 38,适用季节:不限季节","brandName":"new balance","price":259.0,"monthPrice":259.0,"quantity":0,"monthSellAmount":8151,"monthSellMoney":2111109.0,"sellAmount":365,"sellMoney":94535.0,"category":"50012347","catName":"童装玩具/孕产/用品--童鞋/婴儿鞋/亲子鞋--靴子/雪地靴","uid":"1119887712","shopName":"newbalance童鞋旗舰店","shopType":"商城","publishTime":null},{"date":"2017-12-03 00:00:00","numberId":"533962431848","title":"New Balance 男童鞋秋冬运动鞋中童鞋儿童鞋子男休闲鞋女KV373Z1Y","picUrl":"//g-search3.alicdn.com/img/bao/uploaded/i4/i4/1119887712/TB1Od1bbkfb_uJkHFrdXXX2IVXa_!!0-item_pic.jpg","loc":"江苏苏州","propertyValue":"适用性别:女 男 中性,品牌:NEW BALANCE,货号:KV373Z1Y,鞋底材质:橡胶,上市年份季节:2016年秋季,运动鞋分类:休闲鞋,功能:耐磨,颜色分类:KV373Z5Y/灰色 KV373Z1Y/藏青色 KV373Z6Y/红色 KV373Z2Y/橄榄绿,尺码:28 28.5 30 31 32.5 33.5 35 35.5 36,适用季节:不限季节","brandName":"new balance","price":189.0,"monthPrice":189.0,"quantity":0,"monthSellAmount":12724,"monthSellMoney":2404836.0,"sellAmount":374,"sellMoney":70686.0,"category":"50012341","catName":"童装玩具/孕产/用品--童鞋/婴儿鞋/亲子鞋--运动鞋","uid":"1119887712","shopName":"newbalance童鞋旗舰店","shopType":"商城","publishTime":null},{"date":"2017-12-03 00:00:00","numberId":"553687087296","title":"New Balance 小童短靴雪地靴冬季 女童靴子秋冬短靴加绒FB996SXI","picUrl":"//g-search2.alicdn.com/img/bao/uploaded/i4/i1/1119887712/TB1_Q5vf0bJ8KJjy1zjXXaqapXa_!!0-item_pic.jpg","loc":"江苏苏州","propertyValue":"适用性别:女 男 中性,品牌:NEW BALANCE,货号:FB996S4I,鞋底材质:橡胶,上市年份季节:2017年秋季,颜色分类:FB996S3I/肉粉色 FB996SQI/桔色 FB996SXI/墨绿色,尺码:21 22.5 23.5 25 26 27.5,适用季节:不限季节","brandName":"new balance","price":199.0,"monthPrice":199.0,"quantity":0,"monthSellAmount":6278,"monthSellMoney":1249322.0,"sellAmount":273,"sellMoney":54327.0,"category":"50012347","catName":"童装玩具/孕产/用品--童鞋/婴儿鞋/亲子鞋--靴子/雪地靴","uid":"1119887712","shopName":"newbalance童鞋旗舰店","shopType":"商城","publishTime":null},{"date":"2017-12-03 00:00:00","numberId":"560634778264","title":"New Balance/NB 17男女款长款加厚羽绒服NCNP/NP746052/NP746021","picUrl":"//g-search1.alicdn.com/img/bao/uploaded/i4/i5/TB1vATWa2al9eJjSZFzYXGITVXa_M2.SS2","loc":"江西南昌","propertyValue":"品牌:NEW BALANCE,上市时间:2017年冬季,运动系列:运动生活系列,运动户外项目:运动休闲,款号:NP746052,颜色分类:男黑色NP746021BK，女黑色NP746052BK，NP746021-BEI,吊牌价:1699,性别:女","brandName":"new balance","price":1088.0,"monthPrice":1088.0,"quantity":0,"monthSellAmount":272,"monthSellMoney":295936.0,"sellAmount":26,"sellMoney":28288.0,"category":"50011721","catName":"运动/户外/乐器--运动服/休闲服装--运动羽绒服","uid":"1659771931","shopName":"小靓仔正品","shopType":"C店","publishTime":"2017-10-31 00:00:00.0"},{"date":"2017-12-03 00:00:00","numberId":"45770516761","title":"New Balance/NB 373系列 女鞋复古跑步鞋 休闲鞋WL373AE","picUrl":"//g-search3.alicdn.com/img/bao/uploaded/i4/i2/TB1umkbSpXXXXb9XpXXXXXXXXXX_!!0-item_pic.jpg","loc":"江苏苏州","propertyValue":"品牌:NEW BALANCE,鞋码:36 38 37.5 36.5 40 35 37 39,外底材料:橡胶,是否瑕疵:否,运动鞋科技:耐磨橡胶外底,性别:女子,上市时间:2015年秋季,运动系列:女鞋-复古鞋,款号:2015Q3WL373AD,功能:减震 耐磨 包裹性,颜色分类:藏青色 墨绿色,帮面材质:织物+人造革  人造革+织物,适合路面:小道 公路,是否商场同款:是,吊牌价:519,闭合方式:系带","brandName":"new balance","price":259.0,"monthPrice":259.0,"quantity":0,"monthSellAmount":9456,"monthSellMoney":2449104.0,"sellAmount":99,"sellMoney":25641.0,"category":"50012036","catName":"运动/户外/乐器--运动鞋new--跑步鞋","uid":"520557274","shopName":"New Balance旗舰店","shopType":"商城","publishTime":null},{"date":"2017-12-03 00:00:00","numberId":"553260004103","title":"New Balance nb童鞋 男童鞋秋季 儿童运动鞋男童中大童KV373RDY","picUrl":"//g-search3.alicdn.com/img/bao/uploaded/i4/i4/1119887712/TB1iWq0fZbI8KJjy1zdXXbe1VXa_!!0-item_pic.jpg","loc":"江苏苏州","propertyValue":"适用性别:女 男 中性,品牌:NEW BALANCE,货号:KV373GEY-,鞋底材质:橡胶,上市年份季节:2017年秋季,颜色分类:KV373GEY/绿色 KV373RDY/红色,尺码:28 28.5 30 31 32.5 33.5 35 35.5 36 37 37.5 38 38.5 39 40,适用季节:不限季节","brandName":"new balance","price":209.0,"monthPrice":209.0,"quantity":0,"monthSellAmount":6570,"monthSellMoney":1373130.0,"sellAmount":122,"sellMoney":25498.0,"category":"50012341","catName":"童装玩具/孕产/用品--童鞋/婴儿鞋/亲子鞋--运动鞋","uid":"1119887712","shopName":"newbalance童鞋旗舰店","shopType":"商城","publishTime":null},{"date":"2017-12-03 00:00:00","numberId":"43793759415","title":"New Balance/NB 368系列 男鞋跑步鞋运动休闲鞋M368JBK","picUrl":"//g-search1.alicdn.com/img/bao/uploaded/i4/i1/520557274/TB1g5HacMDD8KJjy0FdXXcjvXXa_!!0-item_pic.jpg","loc":"江苏苏州","propertyValue":"品牌:NEW BALANCE,鞋码:40 40.5 41.5 42 42.5 43 44 45,外底材料:橡胶,是否瑕疵:否,性别:男子,上市时间:2015年春季,运动系列:男鞋-复古鞋,款号:2015Q1M368AN,功能:减震 耐磨 包裹性,颜色分类:黑色 深棕色,帮面材质:人造革+织物,适合路面:小道 公路,是否商场同款:是,流行元素:车缝线,吊牌价:519,闭合方式:系带","brandName":"new balance","price":259.0,"monthPrice":259.0,"quantity":0,"monthSellAmount":47778,"monthSellMoney":1.2374502E7,"sellAmount":98,"sellMoney":25382.0,"category":"50012036","catName":"运动/户外/乐器--运动鞋new--跑步鞋","uid":"520557274","shopName":"New Balance旗舰店","shopType":"商城","publishTime":null},{"date":"2017-12-03 00:00:00","numberId":"560654449509","title":"New Balance 17男女情侣中长款羽绒服外套NCNP/NP746052/NP746021","picUrl":"//g-search3.alicdn.com/img/bao/uploaded/i4/i3/651497337/TB2BmA_fNPI8KJjSspoXXX6MFXa_!!651497337.jpg","loc":"浙江杭州","propertyValue":"品牌:NEW BALANCE,服装款式细节:品牌LOGO，贴袋,衣门襟:拉链,衣长:中长款,性别:男女通用,上市时间:2017年冬季,运动系列:基本系列,运动户外项目:户外运动,款号:NCNP746052,功能:抗紫外线，保暖，耐磨，超轻，防风,领型:连帽,填充物:70%灰鸭绒,吊牌价:1699","brandName":"new balance","price":1128.0,"monthPrice":1128.0,"quantity":0,"monthSellAmount":204,"monthSellMoney":230112.0,"sellAmount":22,"sellMoney":24816.0,"category":"50011721","catName":"运动/户外/乐器--运动服/休闲服装--运动羽绒服","uid":"651497337","shopName":"源本体育","shopType":"C店","publishTime":"2017-10-31 00:00:00.0"},{"date":"2017-12-03 00:00:00","numberId":"547548114586","title":"New Balance/NB 373系列女休闲运动鞋WL373PP","picUrl":"//g-search1.alicdn.com/img/bao/uploaded/i4/i4/TB1XeXCQpXXXXXKXFXXXXXXXXXX_!!0-item_pic.jpg","loc":"江苏苏州","propertyValue":"品牌:NEW BALANCE,鞋码:35 36 36.5 37 37.5 38 39 40,外底材料:橡胶,是否瑕疵:否,性别:女子,上市时间:2017年夏季,运动系列:女鞋-复古鞋,款号:2017Q2WL373PP,功能:减震 耐磨 包裹性,颜色分类:浅粉红色,帮面材质:牛剖层革+织物+人造革,适合路面:小道 公路,是否商场同款:是,流行元素:车缝线,吊牌价:519,闭合方式:系带","brandName":"new balance","price":363.3,"monthPrice":363.3,"quantity":0,"monthSellAmount":606,"monthSellMoney":220159.8,"sellAmount":66,"sellMoney":23977.8,"category":"50012036","catName":"运动/户外/乐器--运动鞋new--跑步鞋","uid":"520557274","shopName":"New Balance旗舰店","shopType":"商城","publishTime":null},{"date":"2017-12-03 00:00:00","numberId":"542835752857","title":"New Balance 女童小白鞋秋 儿童小白鞋女 运动鞋男小童鞋KV373AWI","picUrl":"//g-search3.alicdn.com/img/bao/uploaded/i4/i2/1119887712/TB1ec97f22H8KJjy1zkXXXr7pXa_!!0-item_pic.jpg","loc":"江苏苏州","propertyValue":"适用性别:中性,品牌:NEW BALANCE,货号:KV373AWI,上市年份季节:2017年春季,颜色分类:KV373AWI/白色 KV373ABI/黑色,学步鞋鞋底材质:橡胶,尺码:23.5 25 26 27.5,适用季节:不限季节,婴儿鞋类型:学步鞋,闭合方式:魔术贴","brandName":"new balance","price":159.0,"monthPrice":159.0,"quantity":0,"monthSellAmount":4839,"monthSellMoney":769401.0,"sellAmount":147,"sellMoney":23373.0,"category":"50012345","catName":"童装玩具/孕产/用品--童鞋/婴儿鞋/亲子鞋--学步鞋/婴儿步前鞋","uid":"1119887712","shopName":"newbalance童鞋旗舰店","shopType":"商城","publishTime":null}],"count":1000}};
    setTimeout(() => {

      this.vm.table.products = res.data.value;

      this.vm.table.count = res.data.count;

    }, 100);
  }


  export(){

    let dim = ['date','numberId','title','picUrl','loc','propertyValue','brandName','price','monthPrice','monthSellAmount','monthSellMoney','sellAmount','sellMoney','category','catName','uid','shopName','shopType'];

    let dimText = ['时间','宝贝Id','宝贝标题','宝贝图片链接','地址','属性','品牌名','成交均价','月成交均价','月销售量','月销售额','销售量','销售额','类目id','类目','店铺id','店铺名','店铺类型'];
      
    let fileName = this.brandInfo.brandName+this.param.catName+this.param.shopType+"全部宝贝";


    this.productExport(this.param,dim,dimText,fileName);
  }

}
